<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>会员详情</title>
<link href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/plugins/datapicker/datepicker3.css">
<style type="text/css">
.form-control{width:90%;}
</style>
</head>
<body>
<div class="container-fluid">
	<div class="panel-group" id="accordion">
	    <div class="panel panel-default">
	        <div class="panel-heading">
	            <h5 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="tabs_panels.html#collapseOne" aria-expanded="false" class="collapsed">
                    	基础信息</a>
                </h5>
	        </div>
	        <div id="collapseOne" class="panel-collapse collapse in" aria-expanded="true">
	            <div class="panel-body">
	            	<table style="width: 100%;border-collapse:separate; border-spacing:0px 8px;">
	            		<tr>
	            			<td>手机号</td>
	            			<td><input id="phone" class="form-control" readOnly="readOnly"> </td>
	            			<td>姓名</td>
	            			<td><input id="name" class="form-control" readOnly="readOnly"> </td>
	            			<td>微信号</td>
	            			<td><input id="weixin" class="form-control" readOnly="readOnly"> </td>
	            		</tr>
	            		<tr>
	            			<td>性别</td>
	            			<td>
	            				<select id="sex" class="form-control" readOnly="readOnly">
	            					<option value="m">男</option>
	            					<option value="f">女</option>
	            				</select> </td>
	            			<td>生日</td>
	            			<td><input id="birthday" class="form-control" readOnly="readOnly"> </td>
	            			<td>年龄</td>
	            			<td><input id="age" readonly="readonly" class="form-control"> </td>
	            		</tr>
	            		<tr>
	            			<td>邮箱</td>
	            			<td><input id="email" class="form-control" readOnly="readOnly"> </td>
	            			<td>QQ</td>
	            			<td><input id="QQ" class="form-control" readOnly="readOnly"> </td>
	            			<td>省份</td>
	            			<td><select id="province" onchange="func_getCity(this.value)" class="form-control" readOnly="readOnly"><option value="">请选择</option></select> </td>
	            		</tr>
	            		<tr>
	            			<td>会员状态</td>
	            			<td>
	            				<select id="type" class="form-control" readOnly="readOnly">
	            					<option value="1">正常</option>
	            					<option value="2">冻结</option>
	            				</select></td>
	            			<td>城市</td>
	            			<td><select id="city" class="form-control" readOnly="readOnly"><option value="">请选择</option></select> </td>
	            			<td>微博</td>
	            			<td><input id="weibo" class="form-control" readOnly="readOnly"> </td>
	            		</tr>
	            		<tr>
	            			<td>会员等级</td>
	            			<td><input id="level" class="form-control" readonly="readonly"> </td>
	            			<td>会员积分</td>
	            			<td><input id="point" class="form-control" readonly="readonly"> </td>
	            			<td>会员储值</td>
	            			<td><input id="cash" class="form-control" readonly="readonly"> </td>
	            		</tr>
	            		<tr>
	            			<td>所属门店</td>
	            			<td><input id="store_name" class="form-control" readonly="readonly"> </td>
	            			<td>所属销售</td>
	            			<td><input id="market_name" class="form-control" readonly="readonly"> </td>
	            			<td></td>
	            			<td></td>
	            		</tr>
	            	</table>
	            	<br/>
	            </div>
	        </div>
	    </div>
	</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var memberId = getUrlParam("memberId");

$(function(){
	$("#birthday").datepicker({keyboardNavigation:!1,forceParse:!1,autoclose:!0});
	init();
});

function init(){
	$.post(path+"/member/ajaxGetMember",{id:memberId},function(data){
		if(data.status == "200"){
			var member = data.data;
			
			$("#phone").val(member.phone);
			$("#name").val(member.name);
			$("#weixin").val(member.wechat);
			$("#sex").val(member.gender);
			var birthday = member.birthday;
			$("#birthday").val(birthday);
			
			var age = "";
			if(birthday != null && birthday != ""){
				var now = new Date();
				var nowYear = now.getFullYear();
				var birthdayYear = birthday.split("-")[0];
				age = nowYear - parseInt(birthdayYear) + 1;
			}
			$("#age").val(age);
			$("#email").val(member.email);
			$("#QQ").val(member.QQ);
			var province = member.province;
			var city = member.city;
			func_getProvince(province,city);
			
			$("#type").val(member.type);
			$("#weibo").val(member.weibo);
			
			$("#level").val(member.level);
			$("#point").val(member.point);
			$("#cash").val(member.cash);
			$("#store_name").val(member.store_name);
			$("#market_name").val(member.market_name);
			
			$("#cost_total").val(member.cost_total);
			$("#cost_count").val(member.cost_count);
			$("#first_cost_time").val(member.first_cost_time);
			$("#last_cost_time").val(member.last_cost_time);
		}
	},"json");
}

function func_updateMember(){
	var phone = $.trim($("#phone").val());
	var name = $.trim($("#name").val());
	var wechat = $.trim($("#weixin").val());
	var gender = $.trim($("#sex").val());
	var birthday = $.trim($("#birthday").val());
	var email = $.trim($("#email").val());
	var QQ = $.trim($("#QQ").val());
	var province = $("#province>option:selected").text();
	var city = $("#city>option:selected").text();
	var weibo = $.trim($("#weibo").val());
	var level = $.trim($("#level").val());
	var type = $("#type").val()
	
	var jsonObject = {};
	jsonObject.id = memberId;
	jsonObject.phone = phone;
	jsonObject.name = name;
	jsonObject.wechat = wechat;
	jsonObject.gender = gender;
	jsonObject.birthday = birthday;
	jsonObject.email = email;
	jsonObject.QQ = QQ;
	jsonObject.province = province;
	jsonObject.city = city;
	jsonObject.weibo = weibo;
	jsonObject.level = level;
	jsonObject.type = type;
	
	$.ajax({
		contentType: 'text/plain;charset=utf-8',
		dataType: 'json',
    	type: 'POST',
    	url: path+"/member/ajaxUpdateMember",
    	data: JSON.stringify(jsonObject),
    	success: function(data){
			if(data.status == "200"){
				alert("保存成功");
    			parent.func_dataTableReload();
			}else if(data.status == "601"){
				alert("会员手机号重复");
			}else{
				alert("远程请求出错");
			}
    	}
	},"json");
}

/**
 * 获取省份
 */
function func_getProvince(provinceName,cityName){
	$.post(path+"/scan/findPeople/getAddress",{parent_code:'001'},function(data){
		var province = data;
		$.each(province,function(i,a){
			$("#province").append('<option value="'+a.code+'">'+a.name+'</option>');
		});
		if(provinceName != undefined){
			$("#province>option").each(function(i,d){
				if($(d).text() == provinceName){
					$(d).attr("selected",true);
					return false;
				}
			});
			
			func_getCity($("#province").val(),cityName);
		}
	},"json");
}

function func_getCity(code,cityName){
	$("#city").html('<option value="">请选择</option>');
	$.post(path+"/scan/findPeople/getAddress",{parent_code:code},function(data){
		var city = data;
		$.each(city,function(i,a){
			$("#city").append('<option value="'+a.code+'">'+a.name+'</option>');
		});
		if(cityName != undefined){
			$("#city>option").each(function(i,d){
				if($(d).text() == cityName){
					$(d).attr("selected",true);
					return false;
				}
			});
		}
	},"json");
}

function getUrlParam(key){
	var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}
</script>
</html>